HashSet in Dart and its methods and properties |
您所在的位置:网站首页 › java hashset hashcode › HashSet in Dart and its methods and properties |
Introduction to HashSet in Dart: The HashSet class of Dart is used for a hash-table based Set implementation. The Set collection is used to hold unique elements, i.e. we can’t have any duplicates in a set. The elements of a HashSet should provide an equivalence relation and should provide an implementation of hashCode. It is unordered. So, the iteration order might differ. The HashSet class provides a couple of properties and methods. Constructors of a HashSet:There are four constructors available for a HashSet. HashSet({bool equals(E, E)?, int hashCode(E)?, bool isValidKey(dynamic)?})This constructor is used to create one HashSet and it uses the equals method as the equality method, hashCode method for the hash-code. HashSet.from(Iterable it)It creates one HashSet with all the items of the iterable it. HashSet.identity()It creates one identity-based HashSet. HashSet.of(Iterable it)Creates one HashSet with all the items of the iterable it. Properties of a HashSet:The following properties are available for a HashSet: isEmpty → boolCheck if the HashSet is empty. isNotEmpty → boolCheck if the HashSet is not empty. length → intGet the length of the HashSet. first → EGet the first element. last → EGet the last element. single → ECheck if it has only one element and returns that. iterator → IteratorGet an iterator to iterate over the HashSet. hashCode → intGet the hashCode. runtimeType → TypeGet the runtime type. Methods of HashSet:The following methods are available for a HashSet: remove(Object? o) → boolIt removes the object o from the HashSet. removeAll(Iterable it) → voidRemove all the elements of the set. clear() → voidIt removes all elements of the HashSet removeWhere(bool fn(E e)) → voidRemoves all elements as defined by the function fn. retainAll(Iterable it) → voidRemoves all elements that are not in the iterable it. retainWhere(bool fn(E e)) → voidRemoves all elements that are failed to the function fn. add(E e) → boolAdd the element e to the HashSet. addAll(Iterable it) → voidAdds all the elements of the iterable it to this set. contains(Object? o) → boolCheck if the object o is in the HashSet or not. containsAll(Iterable it) → boolThis method can be used to check if all the items of the iterable are in the HashSet or not. any(bool fn(E e)) → boolFind if any element in the set satisfies the function fn. every(bool fn(E e)) → boolFind if all elements of the set satisfy the function fn. elementAt(int i) → EReturn the element at index i of the HashSet. firstWhere(bool fn(E element), {E orElse()?}) → EGet the first element that satisfies the fn. singleWhere(bool fn(E element), {E orElse()?}) → EGet the single element that satisfies the fn. lastWhere(bool fn(E element), {E orElse()?}) → EGet the last element that satisfies the fn. lookup(Object? o) → E?Get the element equal to o in the set. difference(Set o) → SetGet a new set with the elements that are in the current set but not in o. intersection(Set o) → SetGet the intersection between the current set and o. union(Set o) → SetGet the union of the elements of the current set and the o. skip(int count) → IterableGet one iterable by skipping the first count elements of the set. skipWhile(bool fn(E e)) → IterableGet one iterable by skipping all the elements defined by the function fn. forEach(void fn(E e)) → voidCall the function fn on each of the elements of the set. map(T toElement(E e)) → IterableModify the elements by the toElement function. take(int count) → IterableGet one lazy iterable of the first count elements of the set. takeWhile(bool fn(E e)) → IterableGet one lazy iterable of the first elements defined by the function fn. where(bool fn(E e)) → IterableGet one lazy iterable of the elements satisfied by the predicate fn. whereType() → IterableGet one lazy iterable of the elements of type T. followedBy(Iterable it) → IterableGet one lazy iterable of this set and it. reduce(E combine(E v, E e)) → EReduce the set to a single value by combining iteratively with the combine function. fold(T initial, T combine(T previous, E element)) → TIt is similar to the reduce function, but it uses an initial value with the combine function. expand(Iterable toElements(E e)) → IterableExpand each of the items of the set to one or more elements. join([String separator = ""]) → StringReturns one string by concatenating the elements of the HashSet. It converts the elements to string. toList({bool growable = true}) → ListIt returns one list with the set elements. toSet() → SetGet one set with the elements of the HashSet. toString() → StringGet the string representation of the HashSet. cast() → SetGet a set of R instance. noSuchMethod(Invocation invocation) → dynamicThis is invoked if any undefined method is called. You might also like:5 ways in Dart to print the multiplication tableIntroduction to Queue in Dart and its methodsHow to add and remove items from a Queue in DartHow to remove and retain items from Queue in Dart with conditionDart Queue reduce function exampleDart HashMap explanation with examplesHow to add and remove items of a HashMap in DartHow to iterate a HashMap in Dart in different ways |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |